<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *挪车记录
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['nickname'])){
		$params['nickname']='%'.trim($_RQ['nickname']).'%';
		$return['params']['nickname']=trim($_RQ['nickname']);
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile like']='%'.trim($_RQ['mobile']).'%';
		$return['params']['mobile']=trim($_RQ['mobile']);
	}
	if(!empty($_RQ['merchid'])){
		$params['merchid']=intval($_RQ['merchid']);
		$return['params']['merchid']=$_RQ['merchid'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_yxgoodserpfw_members',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['tomid']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'经销商信息'),
		),
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'nickname','title'=>'姓名','type'=>'string'),
			array('name'=>'mobile','title'=>'电话','type'=>'string'),
			array('name'=>'cname','title'=>'公司名','type'=>'string'),
			array('name'=>'address','title'=>'地址','type'=>'string'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		)),
		'search'=>array(
			array('name'=>'nickname','width'=>15,'title'=>'姓名','type'=>'string'),
			array('name'=>'mobile','width'=>15,'title'=>'电话','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
    $return['item']=pdo_get('jy_yxgoodserpfw_members',array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'经销商信息',
		'edit'=>array(
			array('name'=>'nickname','title'=>'姓名','type'=>'string'),
			array('name'=>'mobile','title'=>'电话','type'=>'string'),
			array('name'=>'cname','title'=>'公司名','type'=>'string'),
			array('name'=>'address','title'=>'地址','type'=>'string'),
			)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
		'nickname'=>trim($postdata['nickname']),
		'mobile'=>trim($postdata['mobile']),
		'cname'=>trim($postdata['cname']),
		'address'=>trim($postdata['address']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_yxgoodserpfw_members',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=TIMESTAMP;
		pdo_insert('jy_yxgoodserpfw_members',$data);
	}
	exi('设置成功','','list');
}
if($_RQ['op']=='del'){
	exi('不能删除！！','error');
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_yxgoodserpfw_members',array('id'=>$id,'merchid'=>$_SESSION['onemerchid']));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_yxgoodserpfw_members',array('id'=>$id,'merchid'=>$_SESSION['onemerchid']));
			}
		}
	}
	exi('删除成功！');
}